import { isEmpty } from 'lodash'

const keysOfChina = {
  rtuId: 'rtuId',
  rtu_module: 'rtu模块',
  rtuSimType: 'rtu类型',
  rtuNo: 'rtu编号',
  rtuTelePhone: 'rtu电话',
  unitTele: '联系电话',
  unitAdmin: '联系人员',
  areaId: '片区id',
  unitName: '用户姓名',
  unitCode: '用户编码',
  unitAddress: '用户地址',
  maxPress: '额定最大压力',
  meterInitScale: '初次读数',
  maxValue: '额定最大流量',
  latitude: '纬度',
  maxTemp: '额定最大温度',
  deviceNo: '设备编号',
  modelNo: '表型号',
  meterGasClass: '用气性质',
  minTemp: '额定最小温度',
  minPress: '额定最小压力',
  minValue: '额定最小流量',
  meterAdd: '安装地址',
  meterId: '表具id',
  meterType: '表类型',
  meterNo: '表通讯号',
  unitId: '用户id',
  meterInstallTime: '安装时间',
  sector: '次级部门',
  longitude: '经度',
  addressInfo: '安装信息'
}

export default {
  backgroundColor: '#1c213e',
  tooltip: {
    trigger: 'item',
    triggerOn: 'mousemove',
    appendToBody: true,
    formatter: function(val) {
      const { data = {} } = val
      return data.value
    }
  },
  series: [
    {
      type: 'tree',
      top: '1%',
      left: '1%',
      bottom: '1%',
      right: '20%',
      symbolSize: 8,
      itemStyle: {
        color: '#333'
      },
      label: {
        position: 'left',
        verticalAlign: 'middle',
        align: 'right',
        fontSize: 12,
        color: '#fff',
        formatter: function(val) {
          const { data = {}, value } = val
          if (!keysOfChina || isEmpty(keysOfChina)) {
            return data.name
          }
          const labelValue = keysOfChina[data.name]
            ? value == null
              ? keysOfChina[data.name]
              : keysOfChina[data.name] + ': ' + value
            : ''
          return labelValue
        }
      },
      lineStyle: {
        color: 'rgba(140, 182, 247, 0.3)'
      },
      leaves: {
        label: {
          position: 'top',
          verticalAlign: 'top',
          align: 'left',
          offset: [0, -5]
        }
      },

      expandAndCollapse: true,
      animationDuration: 550,
      animationDurationUpdate: 750
    }
  ]
}
